, open the database, go under the Scripts menu and select
First Custom Menu Item
from the External menu. Choosing the custom menu item will display a simple dialog telling you which menu item was selected.
NOTE:
- Versions 1.1 of this example adds the quit handler to delete the custom menu items.
-To be able to select a custom menu, a database must first be open.
-Menus and menu items are objects that belong ]
only to the FileMaker application object. When creating the menu items with AppleScript, make sure that the
Create
event is directed at the application object as shown in the
Open MenuMaker applet
Quit MenuMaker applet
Open MenuMaker applet
pplet
InfoB
Creating Custom Menus in FileMaker Pro Using AppleScript
An example of how you can use Apple events and AppleScript to create custom menu items in FileMaker Pro.
[NOTE: This script assumes you are using version FileMaker Pro 3.0 or greater. It is also recommended that you have the following versions of software: System 7.1.1 or System 7.5; AppleScript 1.1]
BACKGROUND
FileMaker Pro allows you to create hierarchical menus and menu items that appear in a menu called
This file shows an example of how you can use Apple events and AppleScript to create custom menu items in FileMaker Pro.
To see how this works, go under the Scripts menu and select
First Custom Menu Item
from the External menu. Choosing the custom menu item will display a simple dialog telling you which menu item was selected.
An applet called
MenuMaker
is responsible for creating the menu items and handling them. For more information, click on the
button.
InfoF5Creating Custom Menus in FileMaker
using AppleScript menu. Choosing the custom menu item will display a simple dialog telling you which menu item was selected.
An applet called
MenuMaker
is responsible for creating the menu items and handling them. For more information, click on the
button.
ander Broquet
Scripts menu. This allows you to send commands to an application you have developed or to an applet created with AppleScript. In order for the technique to work, you send an Apple event to the FileMaker Pro application that creates the menu item. When an end-user selects the menu item, FileMaker Pro sends a
Menu Selected
event to the application that created it. That means your application or applet needs to be able to receive and handle this Apple event.
For more information on men
us and menu items, see the
Apple Events Reference
database located in the FileMaker and Apple Events folder of the FileMaker Pro application folder.
CREATING THE SCRIPT
For this example, we will create two menu items. Selecting one of the custom menu items will display a simple dialog saying which menu item was chosen. To do this, first create a script with the AppleScript Script Editor called
MenuMaker
and save it as an application (check the options to
Stay open
and
Never show
startup screen
). Here is the entire script:
--create the menu items
tell application "FileMaker Pro"
Create Menu Item With Properties {Name:"First Custom Menu Item", ID:111, Enabled:true}
Create Menu Item With Properties {Name:"Second Custom Menu Item", ID:222, Enabled:true}
activate
end tell
--handle the menu items
event kMENkMIS
menuName
tell me to activate
if menuName = "First Custom Menu Item" then
display dialog "First menu item was selected
else if menuName = "Secon
d Custom Menu Item" then
display dialog "Second menu item was selected
end if
tell application "FileMaker Pro" to activate
event kMENkMIS
--delete the menu items
on quit
tell application "FileMaker Pro"
Delete Menu Item "First Custom Menu Item"
Delete Menu Item "Second Custom Menu Item"
end tell
continue quit
end quit
Next, create a ScriptMaker script in FileMaker called
Open MenuMaker applet
that uses the
Send Apple Event
command to send an
Open Application
Back to Example
display a simple dialog telling you which menu item was selected.
NOTE:
- Versions 1.1 of this example adds the quit handler to delete the custom menu items.
-To be able to select a custom menu, a database must first be open.
-Menus and menu items are objects that belong only to the FileMaker application object. When M
creating the menu items with AppleScript, make sure that the
Create
event is directed at the application object as shown in the
Back to Example
Alexander Broquet
menu item. When an end-user selects the menu item, FileMaker Pro sends a
Menu Selected
event to the application that created it. That means your application or applet needs to be able to receive and handle this Apple event.
For more information on men
us and menu items, see the
Apple Events Reference
database located in the FileMaker and Apple Events folder of the FileMaker Pro application folder.
CREATING THE SCRIPT
For this example, we will create two menu items. Selecting one of the custom menu items will display a simple dialog saying which menu item was chosen. To do this, first create a script with the AppleScript Script Editor called
MenuMaker
and save it as an application (check the options to
Stay open
and
Never show
enu was selected. In this example, we simply display a dialog that tells which menu was selected. Finally we return the focus back to FileMaker using the activate command.
Finally, the quit handler tells FileMaker Pro to delete the custom menus when the MenuMaker applet receives a quit event.
RUNNING THE SCRIPT
To see how this works, open the database, go under the Scripts menu and select
First Custom Menu Item
from the External menu. Choosing the custom menu item will display a simpl
re dialog telling you which menu item was selected.
NOTE:
-To be able to select a custom menu, a database must first be open.
-Menus and menu items are objects that belong only to the FileMaker application object. When creating the menu items with AppleScript, make sure that the
Create
event is directed at the application object as shown in the object hierarchy.
ker called
Open MenuMaker applet
that uses the
Send Apple Event
command to send an
Open Application
ivate command is used to make sure FileMaker is in the foreground.
Handle the menu items
section of the script is designed to receive and handle the "Menu Selected" event which has a class ID of "kMEN" and an event ID of "kMIS". When an external menu item is selected, FileMaker sends this event to the applet along with the name of the menu item chosen. The handler in the applet stores the name of the menu item in a variable called "menuName".
Although it is not widely documen
ted, AppleScript has the ability to process
Apple events within an applet. To do this you create a handler using the
syntax, followed by the word
event
, the class ID and the event ID - all enclosed within chevrons. To create the chevron characters
, use option-\ and shift-option-\.
tell me to activate
statement brings the applet to the foreground so the dialog will be visible and active. Next, an "If" statement is used to take different actions depending on which m
nt to the
MenuMaker
applet. The options for
Bring target application to foreground
and
Wait for event completion before continuing
should not be checked.
Finally, select Preferences
from the File menu, click on Document, and select the
Open MenuMaker applet
script to perform upon startup. This ensures that the menu items are always available when the database is in use. It also makes the processing of the menu commands quick and direct because the applet is already open.
W IT WORKS
The "Create" event which appears on the third and fourth lines of the script is used to make a new menu item which appears under the "External" menu of the "Scripts" menu. Use the "with properties" modifier to specify the name, ID (a number you choose), and the enabled property. The enabled property allows you to determine when the menu item is available to the end-user. Setting this property to true enables the menu item, making it appear in bold in the External menu. The act